package com.jsmtr.rms.controller.DUserResume;

import cn.ktjk.DataTableUtile.DataTable.DataRow;
import cn.ktjk.DataTableUtile.DataTable.DataTable;
import com.jsmtr.rms.entity.*;
import com.jsmtr.rms.service.*;
import com.jsmtr.rms.utils.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * 应聘者变更岗位控制
 * @author: cyx
 * @description:
 * @date: Created in 2019/2/25 16:06
 * @modified by:
 */
@Controller
public class DUserResumeChangeJobController {

    @Resource
    private IUtilService utilService;
    @Resource
    private IProjectService projectService;
    @Resource
    private IDoBSService bsService;
    @Resource
    private IDoMSService msService;

    @Resource
    private IDoResumeService doResumeService;

    @Resource
    private IDoZZService doZZService;

    @Resource
    private IDoSZService szService;

    @Resource
    private IRecommendService recommendService;

    @Resource
    private IDoConfirmService iDoConfirmService;



    @RequestMapping("/DUserResume/RecommendPost")
    public String RecommendPost(HttpServletRequest request, Model model) {
        try {
            model.addAttribute("path", request.getContextPath());
            String pid = request.getParameter("pid").trim();
            String fid = request.getParameter("fid").trim();
            String deptcode = request.getParameter("deptcode").trim();

            model.addAttribute("pid", pid);
            model.addAttribute("fid", fid);
            model.addAttribute("deptcode", deptcode);

            //招聘岗位
            List<ProjectInfoJobs> jobs = projectService.getjobsbypid(pid);
            StringBuilder dstr = new StringBuilder();
            for (ProjectInfoJobs job : jobs) {
                dstr.append("<option value='" + job.getId() + "'>" + job.getJobname() + "</option>");
            }
            model.addAttribute("jobs", dstr);

            String[] ids = request.getParameterValues("id");
            StringBuffer rs = new StringBuffer();
            StringBuffer _ids = new StringBuffer();
            List<DUserResume> resumes;
            if(pid.toUpperCase().indexOf("C_")>=0){ //判断是否高中职秋季招聘
                resumes=doResumeService.getResumes(ids);
                if (resumes==null||resumes.size()<=0){
                   List<HRZZUser> hrzzusers= doZZService.getUsers(ids);
                   if (hrzzusers!=null&&hrzzusers.size()>0){
                       resumes=new ArrayList<>();
                       for (HRZZUser hrzzuser : hrzzusers) {
                           resumes.add(doZZService.getResume(hrzzuser.getCode(),hrzzuser.getPid()));
                       }
                   }
                }

            }else{
                resumes = doResumeService.getResumes(ids);
            }
            if (resumes!=null&&resumes.size()>0) {
                for (DUserResume resume : resumes) {
                    //if (resume.getFid().equals(fid) && resume.getFqstate().equals("未放弃") && resume.getNrid() == null) {
                    if ( resume.getFqstate().equals("未放弃") ) {//20190307取消流程环节判断
                        rs.append("<tr><td>" + resume.getCode() + "</td><td>" + resume.getJname() + "</td><td>" + resume.getName() + "</td>");
                        rs.append("<td>" + resume.getSexname() + "</td><td>" + resume.getCardno() + "</td></tr>");

                        _ids.append("<input type='hidden' name='id' value='" + resume.getId() + "'/>");
                    }
                }
            }else{
                rs.append("<tr><td colspan=8>未找到符合条件的数据!</td></tr>");
            }
            model.addAttribute("rs", rs);
            model.addAttribute("ids", _ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "/Do/UserResume/rpost";
    }

    @RequestMapping("/DUserResume/MatchingPost")
    public String MatchingPost(HttpServletRequest request, Model model) {

            model.addAttribute("path", request.getContextPath());
            String pid = request.getParameter("pid").trim();
            String fid = request.getParameter("fid").trim();
            String deptcode = request.getParameter("deptcode").trim();

            model.addAttribute("pid", pid);
            model.addAttribute("fid", fid);
            model.addAttribute("deptcode", deptcode);
            return "/Do/UserResume/matchingpost";
    }

    @RequestMapping(value = "/DUserResume/MatchingPostAction", method = RequestMethod.POST)
    @ResponseBody
    public ResultBean MatchingPostAction(@RequestParam("excel") MultipartFile file, HttpServletResponse response, HttpServletRequest request){
            String pid = request.getParameter("pid").trim();
            String fid = request.getParameter("fid").trim();
            String deptcode = request.getParameter("deptcode").trim();
            DataTable dataTable=null;
            org.apache.poi.ss.usermodel.Workbook workbook;
            ResultBean resultBean=new ResultBean();
            HttpSession session=request.getSession();
            Integer excel_totalNum=0;
            Integer excel_errorNum=0;
            Integer excel_successNum=0;
            List recommendList=new ArrayList();

            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom"));
            _map.put("ageto", request.getParameter("ageto"));
            _map.put("heightfrom", request.getParameter("heightfrom"));
            _map.put("heightto", request.getParameter("heightto"));
            _map.put("rcount",request.getParameter("rcount"));
            _map.put("usercontent", request.getParameter("usercontent"));
            _map.put("ischangejob",request.getParameter("ischangejob"));
            _map.put("msplan", request.getParameter("msplan"));
            _map.put("msplantime", request.getParameter("msplantime"));
            try{
                try{
                    //Excel转换为DataTable
                    dataTable= ExcelHelper.ReadExcelToDataTable(file);
                }catch (Exception e){
                    resultBean.setState(false);
                    resultBean.setMessage("只能上传后缀为：xls和xlsx的Excel文件");
                    resultBean.setUrl("no");
                    return  resultBean;
                }
                if (dataTable!=null&&dataTable.Rows.size() > 0) {
                    Integer cardNoIndex=null;
                    Integer postIndex=null;
                    excel_totalNum=dataTable.Rows.size();
                    session.setAttribute("excel_totalNum",excel_totalNum);
                    for (int i=0;i<dataTable.Columns.size();i++) {
                        String columnName=dataTable.Columns.get(i).ColumnName;
                        if(columnName.indexOf("身份证")>=0){
                            cardNoIndex=i;
                            continue;
                        }
                        if(columnName.indexOf("现岗位")>=0||columnName.indexOf("岗位")>=0){
                            postIndex=i;
                            continue;
                        }

                    }
                    if(cardNoIndex==null){
                        resultBean.setState(false);
                        resultBean.setMessage("无法识别<span style=color: red>身份证</span>列！");
                        resultBean.setUrl("no");
                        return  resultBean;
                    }
                    if(postIndex==null){
                        resultBean.setState(false);
                        resultBean.setMessage("无法识别岗位列！");
                        resultBean.setUrl("no");
                        return  resultBean;
                    }
                    for (DataRow row : dataTable.Rows) {
                        String cardNo="";
                        if(cardNoIndex!=null){
                            cardNo=row.getValue(cardNoIndex).toString().toUpperCase();
                        }
                        String post="";
                        ProjectInfoJobs projectInfoJobs=null;
                        if(postIndex!=null){
                            post = row.getValue(postIndex).toString();
                            if(post!=null){
                                projectInfoJobs=  projectService.getProjectInfoJob(pid,post);
                            }
                        }

                        if(cardNo!=null&&!cardNo.equalsIgnoreCase("")){
                            if(!pid.startsWith("C_")){
                                DUserResume dUserResume = new DUserResume();
                                dUserResume.setCardno(cardNo);
                                dUserResume.setPath(fid);
                                Map userResumeMap=doResumeService.getResumesMap(1,1000,_map,dUserResume);
                                List duserResumeList=(List)userResumeMap.get("list");
                                if (duserResumeList!=null&&duserResumeList.size()>0){
                                    Map<String,Object> oldDUserResume=(Map<String,Object>)duserResumeList.get(0);
                                    String oldJob=oldDUserResume.get("JNAME").toString();
                                    if (projectInfoJobs!=null) {
                                        if (!oldJob.equalsIgnoreCase(projectInfoJobs.getJobname())) {
                                            Map<String,Object> recommendMap=new HashMap<>();
                                            recommendMap.put("ID", oldDUserResume.get("ID"));
                                            recommendMap.put("CARDNO", oldDUserResume.get("CARDNO"));
                                            recommendMap.put("NAME", oldDUserResume.get("NAME"));
                                            recommendMap.put("SEXNAME", oldDUserResume.get("SEXNAME"));
                                            recommendMap.put("OLDJNAME", oldDUserResume.get("JNAME"));
                                            recommendMap.put("OLDJID", oldDUserResume.get("JID"));
                                            recommendMap.put("NEWJNAME", projectInfoJobs.getJobname());
                                            recommendMap.put("NEWJID",projectInfoJobs.getId());
                                            recommendList.add(recommendMap);
                                        }
                                    }
                                }
                            }else{
                                HRZZUser hrzzUser=new HRZZUser();
                                hrzzUser.setCode(cardNo);
                                hrzzUser.setPath(fid);
                                Map hrzzUserMap=recommendService.getUserMap(0,1000,hrzzUser,_map);
                                List hrzzUserList=(List) hrzzUserMap.get("list");
                                if (hrzzUserList!=null){
                                    Map OldHrzzUser=(Map)hrzzUserList.get(0);
                                    String oldJob=OldHrzzUser.get("JNAME").toString();
                                    if (projectInfoJobs!=null) {
                                        if (!oldJob.equalsIgnoreCase(projectInfoJobs.getJobname())) {
                                            Map<String,Object> recommendMap=new HashMap<>();
                                            recommendMap.put("ID", OldHrzzUser.get("ID"));
                                            recommendMap.put("CODE", OldHrzzUser.get("CODE"));
                                            recommendMap.put("NAME", OldHrzzUser.get("NAME"));
                                            recommendMap.put("SEXNAME", OldHrzzUser.get("SEXNAME"));
                                            recommendMap.put("OLDJANE", OldHrzzUser.get("JOB"));
                                            recommendMap.put("NEWJNAME", projectInfoJobs.getJobname());
                                            recommendMap.put("NEWJID",projectInfoJobs.getId());
                                            recommendList.add(recommendMap);
                                        }
                                    }
                                }
                            }

                            excel_successNum++;
                        }else{
                            excel_errorNum++;
                            row.setValue(dataTable.Columns.size()-1,"无法识别身份证号!");
                        }
                        session.setAttribute("excel_totalNum",excel_totalNum);
                        session.setAttribute("excel_errorNum",excel_errorNum);
                        session.setAttribute("excel_successNum",excel_successNum);
                    }
                    org.apache.poi.ss.usermodel.Workbook reusultbook=ExcelHelper.DataTableToExcel(dataTable,"导入结果");
                     resultBean.setState(true);
                     resultBean.setMessage("匹配完成！");
                     resultBean.setUrl("no");
                     resultBean.setDatas(recommendList);
                }else{
                    resultBean.setState(false);
                    resultBean.setMessage("读取Excel文件错误,未读取到导入数据！");
                    resultBean.setUrl("no");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return  resultBean;
    }

    @RequestMapping(value = "/DUserResume/RecommendPostAction", method = RequestMethod.POST)
    public void RecommendPostAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String[] ids = request.getParameterValues("id");//人员信息ID
            if (ids != null) {
                String pid = request.getParameter("pid");
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                String needComfirm=request.getParameter("needConfirm");
                String needReplan=request.getParameter("needReplan");
                BaseUser usr = utilService.getSessionUser(request);

                if (usr.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        String gwcode = request.getParameter("gwcode").trim();
                        String gwname = request.getParameter("gwname").trim();

                        List addList = new ArrayList();
                        List editList = new ArrayList();


                        List<ProjectInfoFlow> projectInfoFlowList = null;
                        if (StringTools.trimNotEmpty(pid)) {
                            projectInfoFlowList = projectService.getThisFlowDept(pid, deptcode);
                        } else {
                            utilService.printJsonResult(false, "读取方案流程失败！", "no", response);
                        }
                        List<DUserResume> resumes = doResumeService.getResumes(ids);
                        for (DUserResume resume : resumes) {
                            if (!gwname.equalsIgnoreCase(resume.getJname())) {
                                String nid = UUID.randomUUID().toString();
                                String recommendId = UUID.randomUUID().toString();
                                ProjectInfoFlow flow = utilService.getFlow(resume.getFid());
                                String rid = resume.getId();
                                String jlsxflow = null;
                                if (projectInfoFlowList.size() > 0) {
                                    for (ProjectInfoFlow projectInfoFlow : projectInfoFlowList) {
                                        String flowName = projectInfoFlow.getFname() == null ? projectInfoFlow.getNickname() : projectInfoFlow.getFname();
                                            if((pid.toUpperCase().indexOf("C_") >= 0)&& (pid.toUpperCase().indexOf("E_") >= 0))  {
                                            if (flowName != null && (flowName.equalsIgnoreCase("毕业生推荐") || flowName.equalsIgnoreCase("简历筛选"))) {
                                                jlsxflow = projectInfoFlow.getId();
                                                break;
                                            }
                                        } else {
                                            if (flowName != null && flowName.equalsIgnoreCase("简历筛选")) {
                                                jlsxflow = projectInfoFlow.getId();
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (needComfirm!=null&&needComfirm.equalsIgnoreCase("需要确认")){
                                    DUserChangeJobApply userApply=new DUserChangeJobApply();
                                    userApply.setId(UUID.randomUUID().toString());
                                    userApply.setAddtime(DateTools.toLenStr(new Date()));
                                    userApply.setAdduserid(usr.getId());
                                    userApply.setAddusername(usr.getUname());
                                    userApply.setState("已保存");
                                    userApply.setResult("已提交");
                                    userApply.setOldjobcode(resume.getJid());
                                    userApply.setOldjobname(resume.getJname());
                                    userApply.setNewjobcode(gwcode);
                                    userApply.setNewjobname(gwname);
                                    if((pid.toUpperCase().indexOf("C_") >= 0)&& (pid.toUpperCase().indexOf("E_") >= 0)){
                                        HRZZUser hrzzUser = doResumeService.getUser(pid, resume.getCardno());
                                        userApply.setFid(hrzzUser.getFid());
                                        userApply.setPid(hrzzUser.getPid());
                                        userApply.setRid(resume.getId());
                                    }else {
                                        userApply.setFid(resume.getFid());
                                        userApply.setPid(resume.getProid());
                                        userApply.setRid(resume.getId());
                                    }
                                    addList.add(userApply);
                                    break;
                                }else{
                                    //region 不需要确认直接执行转岗操作
                                    if (flow != null) {
                                        if((pid.toUpperCase().indexOf("C_") >= 0)&& (pid.toUpperCase().indexOf("E_") >= 0)) {
                                            if (StringTools.trimNotEmpty(jlsxflow)) {
                                                HRZZUser hrzzUser = doResumeService.getUser(pid, resume.getCardno());
                                                ProjectInfoFlow nowFlow =utilService.getFlow(hrzzUser.getFid());
                                                if(StringTools.trimNotEmpty(needReplan)&&needReplan.equalsIgnoreCase("NO")){
                                                    addList = fillNewDUserResumeNotClear(addList, resume, nid, jlsxflow, gwcode, gwname);
                                                    addList = fillNewHrzzuserNotClear(addList, hrzzUser, nid, jlsxflow, gwcode, gwname);
                                                }else{
                                                    addList = fillNewDUserResume(addList, resume, nid, jlsxflow, gwcode, gwname);
                                                    addList = fillNewHrzzuser(addList, hrzzUser, nid, jlsxflow, gwcode, gwname);
                                                }
                                                addList = fillZZUserRecommend(addList, hrzzUser, nid, gwname);

                                                addList = fillDUserRecommend(addList, resume, nid, gwname);
                                                //

                                                editList.add(hrzzUser);
                                                editList.add(resume);
                                                /*if(StringTools.trimNotEmpty(needReplan)){
                                                    needReplan="NO";
                                                }*/
                                                if (StringTools.trimNotEmpty(needReplan)&&needReplan.equalsIgnoreCase("NO")){
                                                    String msfid=null;
                                                    for (ProjectInfoFlow projectInfoFlow : projectInfoFlowList) {
                                                        String flowName=projectInfoFlow.getFname()==null?projectInfoFlow.getNickname():projectInfoFlow.getFname();
                                                        if (flowName.equalsIgnoreCase("面试")){
                                                            addList=copyMsPlan(addList,hrzzUser.getId(),nid,projectInfoFlow.getId());
                                                        }else if (flowName.equalsIgnoreCase("笔试")){
                                                            addList=copyBsPlan(addList,hrzzUser.getId(),nid,projectInfoFlow.getId());
                                                        }else if(flowName.equalsIgnoreCase("实作")){
                                                            addList=copyOpPlan(addList,hrzzUser.getId(),nid,projectInfoFlow.getId());
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            //复制原简历相关信息包括(学历,工作经验,培训信息,获奖情况,家庭成员)
                                            if (StringTools.trimNotEmpty(jlsxflow)) {
                                                addList = fillDUserRecommend(addList, resume, nid, gwname);
                                                if(StringTools.trimNotEmpty(needReplan)&&needReplan.equalsIgnoreCase("NO")){
                                                    addList=fillNewDUserResumeNotClear(addList,resume,nid,null,gwcode,gwname);
                                                }else{
                                                    addList = fillNewDUserResume(addList, resume, nid, jlsxflow, gwcode, gwname);
                                                }
                                                if (StringTools.trimNotEmpty(needReplan)&&needReplan.equalsIgnoreCase("NO")){
                                                    String msfid=null;
                                                    for (ProjectInfoFlow projectInfoFlow : projectInfoFlowList) {
                                                        String flowName=projectInfoFlow.getFname()==null?projectInfoFlow.getNickname():projectInfoFlow.getFname();
                                                        if (flowName.equalsIgnoreCase("面试")){
                                                            addList=copyMsPlan(addList,resume.getId(),nid,projectInfoFlow.getId());

                                                        }else if (flowName.equalsIgnoreCase("笔试")){
                                                            addList=copyBsPlan(addList,resume.getId(),nid,projectInfoFlow.getId());

                                                        }else if(flowName.equalsIgnoreCase("实作")){
                                                            addList=copyOpPlan(addList,resume.getId(),nid,projectInfoFlow.getId());
                                                        }

                                                        addList=copyZysx(addList,resume.getId(),nid,projectInfoFlow.getId(),projectInfoFlow.getPid());
                                                    }
                                                }
                                                editList.add(resume);
                                            }
                                        }
                                    }
                                    //endregion

                                }

                            }
                        }

                        if (needComfirm!=null&&needComfirm.equalsIgnoreCase("需要确认")){
                            if(addList.size()>0){
                                utilService.addList(addList);
                                utilService.printJsonResult(false, "推荐成功！将审核完成后执行转岗操作！", "no", response);
                            }else{
                                utilService.printJsonResult(false, "当前选中的简历不能推荐到该岗位！", "no", response);
                            }
                        }else{
                            if (editList.size() > 0 && addList.size() > 0) {
                                utilService.addList(editList, addList);
                                // utilService.editList(editList, addList);
                                utilService.printJsonResult(true, "推荐成功！", "no", response);
                            }else{
                                utilService.printJsonResult(false, "当前选中的简历不能推荐到该岗位！", "no", response);
                            }
                        }

                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "请选择需要推荐的人员！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    private List copyZysx(List addList,String userid,String nid,String fid,String pid) throws Exception{
        DoZysx doZysx=utilService.getUserZysx(pid,fid,userid);
        if (doZysx!=null){
            DoZysx newDoZysx=new DoZysx();
            BeanTools.Copy(doZysx,newDoZysx);
            newDoZysx.setId(UUID.randomUUID().toString());
            newDoZysx.setUserid(nid);
            newDoZysx.setPid(pid);
            newDoZysx.setFid(fid);
            addList.add(newDoZysx);
        }
        return  addList;
    }

    private List copyConfirm(List addList,String oldmsId,String newmsId) throws Exception{
        DoMSConfirm doMSConfirm=iDoConfirmService.getUserMSComfrim(oldmsId);
        if (doMSConfirm!=null){
            DoMSConfirm newDoMsConfirm=new DoMSConfirm();
            BeanTools.Copy(doMSConfirm,newDoMsConfirm);
            newDoMsConfirm.setId(UUID.randomUUID().toString());
            newDoMsConfirm.setMsuserid(newmsId);
            addList.add(newDoMsConfirm);
        }
        return  addList;
    }

    private List copyMsPlan(List addList,String userid,String nid,String msfid) throws Exception{
        DoMSUser doMSUser=msService.getMsUser(msfid,userid);
        if (doMSUser!=null){
            DoMSUser newDoMsUser=new DoMSUser();
            BeanTools.Copy(doMSUser,newDoMsUser);
            newDoMsUser.setId(UUID.randomUUID().toString());
            newDoMsUser.setUserid(nid);
            /*newDoMsUser.setOp7(null);
            newDoMsUser.setResult("未面试");
            newDoMsUser.setPoint(null);
            newDoMsUser.setPointdate(null);
            newDoMsUser.setPointuser(null);
            newDoMsUser.setScoringrules(null);
            newDoMsUser.setRemark(null);*/
            addList.add(newDoMsUser);
           addList= copyConfirm(addList,doMSUser.getId(),newDoMsUser.getId());
        }
        return  addList;
    }

    private List copyBsPlan(List addList,String userid,String nid,String bsfid) throws Exception {
        DoBSUser doBSUser=bsService.getBsUser(userid,bsfid);
        if (doBSUser!=null){
            DoBSUser newDoBSUser=new DoBSUser();
            BeanTools.Copy(doBSUser,newDoBSUser);
            newDoBSUser.setId(UUID.randomUUID().toString());
            newDoBSUser.setUserid(nid);
            newDoBSUser.setOp6(null);
            /*newDoBSUser.setResult("-");
            newDoBSUser.setRemark(null);
            newDoBSUser.setGxcppoint(null);
            newDoBSUser.setGxcpresult(null);
            newDoBSUser.setPoint(null);
            newDoBSUser.setPointdate(null);
            newDoBSUser.setPointuser(null);
            newDoBSUser.setZhszpoint(null);
            newDoBSUser.setZhszresult(null);
            newDoBSUser.setZycppoint(null);
            newDoBSUser.setZycpresult(null);*/
            addList.add(newDoBSUser);
        }
        return  addList;
    }

    private List copyOpPlan(List addList,String userid,String nid,String opfid) throws Exception{
        DoOperationUser doOperationUser=szService.getSZUser(opfid,userid);
        if (doOperationUser!=null){
            DoOperationUser newDoOpUser=new DoOperationUser();
            BeanTools.Copy(doOperationUser,newDoOpUser);
            newDoOpUser.setId(UUID.randomUUID().toString());
            newDoOpUser.setUserid(nid);
            newDoOpUser.setOp8(null);
           /* newDoOpUser.setResult("结果未生成");
            newDoOpUser.setPoint(null);
            newDoOpUser.setBz(null);
            newDoOpUser.setPointdate(null);
            newDoOpUser.setPointuser(null);*/

            addList.add(newDoOpUser);
        }
        return  addList;
    }

    private List fillNewDUserResume(List addList,DUserResume resume,String nid,String jlsxflow,String gwcode,String gwname) throws Exception {
        DUserResume nResume = new DUserResume();
        BeanTools.Copy(resume, nResume);
        nResume.setId(nid);
       ProjectInfoFlow flow= utilService.getFlow(resume.getFid());

       /* nResume.setPath("/" + jlsxflow + "/");
        nResume.setFid(jlsxflow);*/
        nResume.setNrid(resume.getId());
        nResume.setRfid(resume.getFid());
        nResume.setNjname(resume.getJname());
        nResume.setJid(gwcode);
        nResume.setJname(gwname);
        nResume.setRecommenddate(DateTools.toLenStr(new Date()));

        nResume.setPath("/" + jlsxflow + "/");
        nResume.setFid(jlsxflow);
        nResume = clearDUserResumeState(nResume);
        //学历信息
        List<DUserEducation> usereducations = doResumeService.getUserEducation(resume.getId());
        for (DUserEducation usereducation : usereducations) {
            DUserEducation dUserEducation = new DUserEducation();
            BeanTools.Copy(usereducation, dUserEducation);
            dUserEducation.setId(UUID.randomUUID().toString());
            dUserEducation.setRid(nid);
            addList.add(dUserEducation);
        }
        //工作经验
        List<DUserWorkExperience> userworkexperiences = doResumeService.getUserWorkExperience(resume.getId());
        for (DUserWorkExperience userworkexperience : userworkexperiences) {
            DUserWorkExperience dUserWorkExperience = new DUserWorkExperience();
            BeanTools.Copy(userworkexperience, dUserWorkExperience);
            dUserWorkExperience.setId(UUID.randomUUID().toString());
            dUserWorkExperience.setRid(nid);
            addList.add(dUserWorkExperience);
        }
        //培训经历
        List<DUserTraining> usertrainings = doResumeService.getUserTraining(resume.getId());
        for (DUserTraining usertraining : usertrainings) {
            DUserTraining dUserTraining = new DUserTraining();
            BeanTools.Copy(usertraining, dUserTraining);
            dUserTraining.setId(UUID.randomUUID().toString());
            dUserTraining.setRid(nid);
            addList.add(dUserTraining);
        }
        //获奖信息
        List<DUserRewardPunishment> userrewardpunishments = doResumeService.getUserRewardPunishment(resume.getId());
        for (DUserRewardPunishment userrewardpunishment : userrewardpunishments) {
            DUserRewardPunishment dUserRewardPunishment = new DUserRewardPunishment();
            BeanTools.Copy(userrewardpunishment, dUserRewardPunishment);
            dUserRewardPunishment.setId(UUID.randomUUID().toString());
            dUserRewardPunishment.setRid(nid);
            addList.add(dUserRewardPunishment);
        }
        //家庭成员
        List<DUserFamily> userfamilys = doResumeService.getUserFamily(resume.getId());
        for (DUserFamily userfamily : userfamilys) {
            DUserFamily dUserFamily = new DUserFamily();
            BeanTools.Copy(userfamily, dUserFamily);
            dUserFamily.setId(UUID.randomUUID().toString());
            dUserFamily.setRid(nid);
            addList.add(dUserFamily);
        }
        addList.add(nResume);
        return  addList;
    }

    private List fillNewDUserResumeNotClear(List addList,DUserResume resume,String nid,String jlsxflow,String gwcode,String gwname) throws Exception {
        DUserResume nResume = new DUserResume();
        BeanTools.Copy(resume, nResume);
        nResume.setId(nid);
        ProjectInfoFlow flow= utilService.getFlow(resume.getFid());

       /* nResume.setPath("/" + jlsxflow + "/");
        nResume.setFid(jlsxflow);*/
        nResume.setNrid(resume.getId());
        nResume.setRfid(resume.getFid());
        nResume.setNjname(resume.getJname());
        nResume.setJid(gwcode);
        nResume.setJname(gwname);
        nResume.setRecommenddate(DateTools.toLenStr(new Date()));
        nResume.setPath(resume.getPath());
        nResume.setFid(resume.getFid());

        //nResume = clearDUserResumeState(nResume);
        //学历信息
        List<DUserEducation> usereducations = doResumeService.getUserEducation(resume.getId());
        for (DUserEducation usereducation : usereducations) {
            DUserEducation dUserEducation = new DUserEducation();
            BeanTools.Copy(usereducation, dUserEducation);
            dUserEducation.setId(UUID.randomUUID().toString());
            dUserEducation.setRid(nid);
            addList.add(dUserEducation);
        }
        //工作经验
        List<DUserWorkExperience> userworkexperiences = doResumeService.getUserWorkExperience(resume.getId());
        for (DUserWorkExperience userworkexperience : userworkexperiences) {
            DUserWorkExperience dUserWorkExperience = new DUserWorkExperience();
            BeanTools.Copy(userworkexperience, dUserWorkExperience);
            dUserWorkExperience.setId(UUID.randomUUID().toString());
            dUserWorkExperience.setRid(nid);
            addList.add(dUserWorkExperience);
        }
        //培训经历
        List<DUserTraining> usertrainings = doResumeService.getUserTraining(resume.getId());
        for (DUserTraining usertraining : usertrainings) {
            DUserTraining dUserTraining = new DUserTraining();
            BeanTools.Copy(usertraining, dUserTraining);
            dUserTraining.setId(UUID.randomUUID().toString());
            dUserTraining.setRid(nid);
            addList.add(dUserTraining);
        }
        //获奖信息
        List<DUserRewardPunishment> userrewardpunishments = doResumeService.getUserRewardPunishment(resume.getId());
        for (DUserRewardPunishment userrewardpunishment : userrewardpunishments) {
            DUserRewardPunishment dUserRewardPunishment = new DUserRewardPunishment();
            BeanTools.Copy(userrewardpunishment, dUserRewardPunishment);
            dUserRewardPunishment.setId(UUID.randomUUID().toString());
            dUserRewardPunishment.setRid(nid);
            addList.add(dUserRewardPunishment);
        }
        //家庭成员
        List<DUserFamily> userfamilys = doResumeService.getUserFamily(resume.getId());
        for (DUserFamily userfamily : userfamilys) {
            DUserFamily dUserFamily = new DUserFamily();
            BeanTools.Copy(userfamily, dUserFamily);
            dUserFamily.setId(UUID.randomUUID().toString());
            dUserFamily.setRid(nid);
            addList.add(dUserFamily);
        }
        addList.add(nResume);
        return  addList;
    }

    private List fillNewHrzzuserNotClear(List addList,HRZZUser hrzzUser,String nid,String jlsxflow,String gwcode,String gwname) throws Exception {
        HRZZUser nhrzzUser = new HRZZUser();
        BeanTools.Copy(hrzzUser, nhrzzUser);
        nhrzzUser.setId(nid);
        //nhrzzUser.setPath("/" + jlsxflow + "/");
        //nhrzzUser.setFid(jlsxflow);
        nhrzzUser.setNrid(hrzzUser.getId());
        nhrzzUser.setRfid(hrzzUser.getFid());
        nhrzzUser.setNjname(hrzzUser.getJob());
        nhrzzUser.setJob(gwname);
        nhrzzUser.setRecommenddate(DateTools.toLenStr(new Date()));
        addList.add(nhrzzUser);
        return addList;
    }

    private List fillNewHrzzuser(List addList,HRZZUser hrzzUser,String nid,String jlsxflow,String gwcode,String gwname) throws Exception {
        HRZZUser nhrzzUser = new HRZZUser();
        BeanTools.Copy(hrzzUser, nhrzzUser);
        nhrzzUser.setId(nid);
        nhrzzUser.setPath("/" + jlsxflow + "/");
        nhrzzUser.setFid(jlsxflow);
        nhrzzUser.setNrid(hrzzUser.getId());
        nhrzzUser.setRfid(hrzzUser.getFid());
        nhrzzUser.setNjname(hrzzUser.getJob());
        nhrzzUser.setJob(gwname);
        nhrzzUser.setRecommenddate(DateTools.toLenStr(new Date()));
        nhrzzUser = clearHRZZUserState(nhrzzUser);

        addList.add(nhrzzUser);
        return addList;
    }


    private List fillDUserRecommend(List addList,DUserResume resume,String nid,String gwname) throws Exception {
        DUserRecommend duserRecommend = new DUserRecommend();
        BeanTools.Copy(resume, duserRecommend);
        String recommendId = UUID.randomUUID().toString();
        if (duserRecommend.getId() != null) {
            duserRecommend.setDuserresumeid(duserRecommend.getId());
            duserRecommend.setId(recommendId);
            duserRecommend.setRfid(resume.getFid());
            duserRecommend.setNjname(gwname);
            duserRecommend.setNrid(nid);
            duserRecommend.setRecommenddate(DateTools.toLenStr(new Date()));
            addList.add(duserRecommend);
        }

        return  addList;
    }

    private List fillZZUserRecommend(List addList,HRZZUser hrzzUser,String nid,String gwname) throws Exception {
        HRZZUserRecommend zzuserRecommend = new HRZZUserRecommend();
        BeanTools.Copy(hrzzUser, zzuserRecommend);
        String recommendId = UUID.randomUUID().toString();
        if (zzuserRecommend.getId() != null) {
            zzuserRecommend.setHrzzuserid(zzuserRecommend.getId());
            zzuserRecommend.setId(recommendId);
            zzuserRecommend.setRfid(hrzzUser.getFid());
            zzuserRecommend.setNjname(gwname);
            zzuserRecommend.setNrid(nid);
            zzuserRecommend.setRecommenddate(DateTools.toLenStr(new Date()));
            addList.add(zzuserRecommend);
        }
        return  addList;
    }

    private String CreateChangeApplyContent(DUserResume resume,String njname){
            StringBuffer result=new StringBuffer();
            result.append(" 姓名:"+resume.getName());
            result.append(" 身份号:"+resume.getCardno());
            result.append(" 招聘方案:"+resume.getProname());
            result.append(" 执行操作:转岗");
            result.append(" 原应聘岗位:"+resume.getJname());
            result.append(" 新应聘岗位:"+njname);
            return result.toString();
    }




    private  HRZZUser clearHRZZUserState(HRZZUser hrzzUser){
        hrzzUser.setFqstate("未放弃");
        hrzzUser.setZsstate("未政审");
        hrzzUser.setZsdate(null);
        hrzzUser.setZsremark(null);
        hrzzUser.setZsuid(null);
        hrzzUser.setZsuname(null);
        hrzzUser.setTjstate("未体检");
        hrzzUser.setTjaddress(null);
        hrzzUser.setTjdate(null);
        hrzzUser.setTjlxdh(null);
        hrzzUser.setTjlxr(null);
        hrzzUser.setTjremark(null);
        hrzzUser.setTjtime(null);
        hrzzUser.setTjuid(null);
        hrzzUser.setTjuname(null);
        hrzzUser.setTjmsg("未发通知");
        hrzzUser.setGwstate("未分配");
        hrzzUser.setBdstate("未报到");
        hrzzUser.setBdaddress(null);
        hrzzUser.setBddate(null);
        hrzzUser.setBdlxr(null);
        hrzzUser.setBdlxdh(null);
        hrzzUser.setBdremark(null);
        hrzzUser.setBdtime(null);
        hrzzUser.setBduid(null);
        hrzzUser.setBduname(null);
        hrzzUser.setBdmsg("未发通知");
        hrzzUser.setQyremark(null);
        hrzzUser.setQystate("未处理");
        hrzzUser.setQyuid(null);
        hrzzUser.setQydate(null);
        hrzzUser.setQyuname(null);
        hrzzUser.setRstate("未处理");
        hrzzUser.setRmarks(null);
        hrzzUser.setOp1("未公布");
        hrzzUser.setOp2("未公布");
        hrzzUser.setOp3("未公布");
        hrzzUser.setOp4("未公布");
        hrzzUser.setOp5("未公布");
        hrzzUser.setOp6("未公布");
        hrzzUser.setOp7("未公布");
        hrzzUser.setOp8("未公布");
        hrzzUser.setOp9("未公布");
        return  hrzzUser;
    }

    private  DUserResume clearDUserResumeState(DUserResume dUserResume){
        dUserResume.setFqstate("未放弃");
        dUserResume.setZlmsg("-");
        dUserResume.setZsstate("未政审");
        dUserResume.setZsdate(null);
        dUserResume.setZsremark(null);
        dUserResume.setZsuid(null);
        dUserResume.setZsuname(null);
        dUserResume.setTjstate("未体检");
        dUserResume.setTjaddress(null);
        dUserResume.setTjdate(null);
        dUserResume.setTjlxdh(null);
        dUserResume.setTjlxr(null);
        dUserResume.setTjremark(null);
        dUserResume.setTjtime(null);
        dUserResume.setTjuid(null);
        dUserResume.setTjuname(null);
        dUserResume.setTjmsg("未发通知");
        dUserResume.setGwstate("未分配");
        dUserResume.setBdstate("未报到");
        dUserResume.setBdaddress(null);
        dUserResume.setBddate(null);
        dUserResume.setBdlxr(null);
        dUserResume.setBdlxdh(null);
        dUserResume.setBdremark(null);
        dUserResume.setBdtime(null);
        dUserResume.setBduid(null);
        dUserResume.setBduname(null);
        dUserResume.setBdmsg("未发通知");
        dUserResume.setQyremark(null);
        dUserResume.setQystate("未处理");
        dUserResume.setQyuid(null);
        dUserResume.setQydate(null);
        dUserResume.setQyuname(null);
        dUserResume.setState("未处理");
        dUserResume.setSxbz(null);
        dUserResume.setOp1(null);
        dUserResume.setOp2(null);
        dUserResume.setOp3(null);
        dUserResume.setOp4(null);
        dUserResume.setOp5(null);
        dUserResume.setOp6(null);
        dUserResume.setOp7(null);
        dUserResume.setOp9(null);

        return  dUserResume;
    }
}
